/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oalam.bookstore.dao;

import com.oalam.bookstore.domain.accounts.Account;
import java.util.ArrayList;
import java.util.List;



/**
 *
 * @author Administrateur
 */
public class MockAccountDao implements AccountDao {
    private List<Account> accounts = new ArrayList<Account>();

    @Override
    public void delete(Account a) {
        accounts.remove(a);
    }

    @Override
    public void deleteAll() {
        accounts.clear();
    }

    @Override
    public void load(Account a) {
        Account tmp = null;
        for (Account account : accounts) {
            if(account.getEmail().equals(a.getEmail()))
                a.clone(account);
        }
        
    }

    @Override
    public void save(Account a) {
        boolean found = false;
        for (Account account : accounts) {
            if(account.getEmail().equals(a.getEmail())){
                account.clone(a);
                found = true;
            }
        }
        if(!found)
            accounts.add(a);
    }

    @Override
    public boolean find(Account a) {
        boolean found = false;
        for (Account account : accounts) {
            if(account.getEmail().equals(a.getEmail())){
                found = true;
            }
        }
        return found;
    }
}
